<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class make_menu
{  
    public $AppId="wxcb83c39afa52a3f9";
    
    public $AppSecret="3dc7c5686fb5ae60960a3012bd85c045";
    
    
    public $openid = "oNh3Hjhk48YIuudfLXMJOjUqg768";
    
    private $ch=null;
    
     //构造函数
    function __construct(){   
        $this->ch = curl_init();
     
    }
    
    
    //获取token
    public function get_access_token()
    {     
            //获取token，页面地址为https://api.weixin.qq.com/cgi-bin/token
            curl_setopt($this->ch,CURLOPT_URL,"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$this->AppId."&secret=".$this->AppSecret);
            curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,true);
            $rst=curl_exec($this->ch);
            if(curl_errno($this->ch)) 
            {
                echo curl_error($this->ch);
                exit;
            }
             else 
            {
               //抓取页面成功，先将抓取的数据转换成数组；
                $rst=json_decode($rst,true);
                 
                 //如果授权失败打印错误代码
                if($rst["errcode"]!=0)
                {
                    echo "获取token失败，错误提示为：".$rst["errmsg"]."，错误代码编号为：".$rst["errcode"];
                    echo "<br><a href='http://mp.weixin.qq.com/wiki/index.php?title=%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E' target='_blank'>错误代码对照表</a>";
                    exit;	
                }
                 //授权成功则将token和过期时间缓存
                else
                {
                    $access_token=$rst["access_token"];
                    $expires_in=$rst["expires_in"];
                    
                    //将获得的token保存到缓存里,过期时间设定为获取的过期时间-60秒
                    

                }
                     
             }
                  //返回token
        return $access_token;
      
    }
    
    
    //获取信息
    public function get_info(){
            //获取信息，页面地址为
        
           // echo $token = $this->get_access_token()."<br>";
            curl_setopt($this->ch,CURLOPT_URL,"https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$this->get_access_token()."&openid=".$this->AppId);
           curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,true);
           $rst=curl_exec($this->ch);
           
            //抓取页面成功，先将抓取的数据转换成数组；
            $rst=json_decode($rst,true);
            foreach ($rst as $value) 
                echo $value;
           
           
    }
    
    
    
}



$make_menu = new make_menu();
$make_menu->get_info();





?>
